/*
 * @Author: 烟浮
 * @Date: 2022-06-26 00:55:37
 * @LastEditTime: 2022-06-26 02:50:20
 * @LastEditors: 锦墨涵秋 275740441@qq.com
 * @FilePath: /vite-ts-vue3/src/api/shop.ts
 */
export interface IProduct {
    id: number
    title: string
    price: number
    inventory: number
}

const _products: IProduct[] = [
    { id: 1, title: 'iPad 4 Mini', price: 500.01, inventory: 2 },
    { id: 2, title: 'Mac Air', price: 10000.01, inventory: 12 },
    { id: 3, title: 'charli XCX - Sucker CD', price: 19.99, inventory: 5 }
]

export const getProducts = async () => {
    await wait(100)
    return _products
}

export const buyProducts = async () => {
    await wait(100)
    return Math.random() > 0.5
}

async function wait(delay: number) {
    return new Promise((resolve) => setTimeout(resolve, delay))
}
